package ConvertPDF;

import java.io.IOException;

import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;

public class Data {

	private String path;
	private PdfReader reader;
	private String page;
	//private Document document;
	
	
	
	public Data(){
		path = "";
		page = "";
	}
	
	public void getPath(String _path){
		path = _path;
	}
	
	public String ReadPdfFile(){
	
		try{
			reader = new PdfReader(path);
			int i = 1;
			while(reader.getNumberOfPages()>i){
				// lay noi dung cua mot trang
				String temp = PdfTextExtractor.getTextFromPage(reader, i);//so i la thu tu trang
				temp = temp.substring(45);
				//xoa so trang trong page
				temp = temp.replace("- "+ i +" -", "");
				page = page + temp;
				i++;
			}
			
			//cong trang cuoi cung
			String lastTemp = PdfTextExtractor.getTextFromPage(reader, i);
			lastTemp = lastTemp.substring(45);
			lastTemp = lastTemp.replace("- "+ i +" -", " +");
			page = page + lastTemp;
			
			System.out.print(page);
			return page;
			
		}
		
		catch (IOException e){
			e.printStackTrace();
			return "";
		}
	}
	
	
}
